/*
 * @lc app=leetcode.cn id=66 lang=cpp
 *
 * [66] 加一
 */

// @lc code=start
class Solution {
public:
    vector<int> plusOne(vector<int>& d) {
        if( ++d[d.size()-1] <10)return d; 
        d[d.size()-1]=0;
        int carry=1;
        for(int i = d.size()-2; i >=0  ;i--){
            d[i]=d[i]+carry;
            if(d[i]==10){
                carry=1;
                d[i]=0;
            }else return d;
       
        }
        d.insert(d.begin(),1);
        return d;
        
    }
};
// @lc code=end

